<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Three.js Video Texture Example</title>
    <style>
        body { margin: 0; }
        canvas { display: block; }
    </style>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script>
    // 创建场景、相机和渲染器
    const scene = new THREE.Scene();
    const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
    const renderer = new THREE.WebGLRenderer();
    renderer.setSize(window.innerWidth, window.innerHeight);
    document.body.appendChild(renderer.domElement);

    // 创建视频元素
    const video = document.createElement('video');
    video.src = './assets/video/1717658488515_3480.mp4'; // 替换为您视频的路径
    video.crossOrigin = 'anonymous'; // 处理跨域问题
    video.loop = true; // 循环播放
    video.muted = true; // 静音，便于自动播放
    video.play(); // 开始播放

    // 创建视频纹理
    const videoTexture = new THREE.VideoTexture(video);

    // 创建平面几何体并应用视频纹理
    const geometry = new THREE.PlaneGeometry(16, 9); // 16:9的比例
    const material = new THREE.MeshBasicMaterial({ map: videoTexture });
    const plane = new THREE.Mesh(geometry, material);
    scene.add(plane);

    // 设置相机位置
    camera.position.z = 5;

    // 监听窗口大小变化
    window.addEventListener('resize', () => {
        const width = window.innerWidth;
        const height = window.innerHeight;
        renderer.setSize(width, height);
        camera.aspect = width / height;
        camera.updateProjectionMatrix();
    });

    // 动画循环
    function animate() {
        requestAnimationFrame(animate);
        renderer.render(scene, camera);
    }
    animate();
</script>
</body>
</html>
